#include <iostream>
#include "people.pb.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv)
{
	int fd = 0;
	struct sockaddr_in server_addr;
	char buff[1024] = {0};

	memset(&server_addr, 0, sizeof(server_addr));
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(8888);
	inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr);

	fd = socket(AF_INET, SOCK_STREAM, 0);
	if(connect(fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0)
	{
		perror("connect error");
		return -1;
	}
	write(fd, "get people",sizeof("get people"));
	int size = read(fd, buff, 1023);
	buff[size] = '\0';
	demo::People people;
	people.ParseFromString(std::string(buff));
	std::cout<<people.name()<<" "<<people.id()<<" "<<people.email()<<std::endl;
	close(fd);

	return 0;
}
